package com.lzwk.app.function;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.apache.flink.table.functions.ScalarFunction;

/**
 * @title: SkinJson
 * @Author Yeaser
 * @Date: 2022/1/5 17:51
 * @Version 1.0
 * Description: TODO
 */
// @FunctionHint(output = @DataTypeHint("row<source_hash_id string>")) 表值函数
public class GetJsonInt extends ScalarFunction {
    public Integer eval(String json, String key,int defaultData){

        if(json == null) {
            return defaultData;
        }else if (json.contains(key)){
            JSONObject jsonObject = JSON.parseObject(json);
            return jsonObject.getInteger(key) == null ? defaultData : jsonObject.getInteger(key);
        }else{
            return defaultData;
        }
    }
}
